﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Exhibition.RenderTemplete.Controls;
using Exhibition.Common.Helper;
using Exhibition.Dao.ViewModel;
using Exhibition.Service;

namespace Exhibition.Manage
{
    public partial class SalesDetail : BaseAdminPage
    {
        SalesModel model = new SalesModel();
        protected void Page_Load(object sender, EventArgs e)
        {

            if (!IsPostBack)
            {
                hfId.Value = reqID.ToString();
                GetSales();
            }

        }

        private void GetSales()
        {

            model = CenterService.salesService.GetOneById(reqID);
            if (model != null)
            {

                //促销方案名称
                txtSaleName.Value = model.SaleName.ToString();

                //比例
                txtSaleProc.Value = model.SaleProc.ToString();

                //开始时间
                txtStartDate.Value = model.StartDate.Value.ToString("yyyy-MM-dd");

                //结束时间
                txtEndDate.Value = model.EndDate.Value.ToString("yyyy-MM-dd");

                

            }

        }

        /// <summary>
        /// 保存一条数据
        /// <summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSave_Click(object sender, EventArgs e)
        {

            model = string.IsNullOrEmpty(hfId.Value)||hfId.Value=="0" ? new SalesModel() : CenterService.salesService.GetOneById(Convert.ToInt32(hfId.Value));
            //促销方案名称
            model.SaleName = txtSaleName.Value;

            //比例
            model.SaleProc = txtSaleProc.Value;

            //开始时间
            model.StartDate = Convert.ToDateTime(txtStartDate.Value);
            model.SiteID = CurrentSite.Id;
            //结束时间
            model.EndDate = Convert.ToDateTime(txtEndDate.Value);
            if (reqID == 0) {
                model.CreateTime = DateTime.Now;
                model.CreateUserId = AdminUser.Id;

            }


            if (CenterService.salesService.Save(model) > 0)
            {

                JsHelper.Unblock(this, CommFunMsg.GetMessage("A0001", Lan.zh));
            }
            else {
                JsHelper.Alert(this,CommFunMsg.GetMessage("E0001",Lan.zh));
            }

        }

    }

}

